package com.yixin.ystartlibrary.utils;

import android.content.Context;
import android.widget.TextView;
import android.widget.Toast;

/**
 * User: Luozi
 * Date: 2015-11-26
 * Content:
 */
public class ToastUtils {

    private static Toast sToast;

    /**
     * 弹出长时间的Toast提示框.
     *
     * @param c    application
     * @param text String
     */
    public static Toast showLongToast(Context c, String text) {
        return show(c, text, Toast.LENGTH_LONG);
    }

    /**
     * 弹出长时间的Toast提示框.
     *
     * @param c    application
     * @param text String
     */
    public static Toast showShortToast(Context c, String text) {
        return show(c, text, Toast.LENGTH_SHORT);
    }

    private static Toast show(Context c, String text, int duration){
        if(sToast == null) {
            sToast = Toast.makeText(c, text, duration);
            TextView textView = (TextView) sToast.getView()
                    .findViewById(android.R.id.message);
            textView.setTextSize(16);
        } else {
            sToast.setText(text);
            sToast.setDuration(duration);
        }
        sToast.show();
        return sToast;
    }
}
